<?php namespace sacvoyage\domain;

require_once('Domain.php');
require_once('Property.php');


require_once('sacvoyage/storage/Database.php');
use \sacvoyage\storage\Database;


class User {

	public function __construct(Domain $domain, $name, Database $database) {
		$this->_domain=$domain;
		if(!$name) {
			throw new Exception('user name must be specified');
		}
		$this->_name=$name;
		$this->_database=$database;
	}

	public function getDomain() {
		return $this->_domain;
	}
	
	public function getName() {
		return $this->_name;
	}

	public function getProperty() {
		if(!$this->_property) {
			$this->_property=new Property($this, $this->_database);
		}
		return $this->_property;
	}
	
	public function getShare($name) {
		$root=$this->getDomain()->loadUser('root');
		$sys_usershares=$root->getProperty()->getCollection('sys.user.share');
		$config=$sys_usershares->read($name);
		$shares=$this->getProperty()->getCollection('sys.share');
		$config=$shares->read($name);
		if($config) {
			return new Share($this->getProperty(), $config);
		} else {
			return null;
		}
	}

	private $_domain;	
	private $_name;	
	private $_database;
	private $_property;	
};


?>
